import requests
import json

def get_CVE():
    headers = {"Content-Type": "application/json;charset=utf8"}
    url = "https://www.openeuler.org/api-euler/api-cve/cve-security-notice-server/cvedatabase/findAll"
    _data = {
          "pages": {
            "page": 1,
            "size": 10000
          },
          "keyword": "",
          "type": "",
          "year": ""
        }

    # 这里使用json参数，即json=_data
    res = requests.post(url=url, headers=headers, json=_data)
    # 当然还可以使用data参数，但需先将_data转换为json格式，即data=json.dumps(_data)
    # json.dumps()将dict格式转换成json格式
    # res = requests.post(url=url, headers=headers, data=json.dumps(_data)).text

    CVE_json = res.json()
    filename = 'CVE.json'
    # 指定了要将该数字列表存储到哪个⽂件中

    with open(filename, 'w', encoding='utf-8') as f:
        json.dump(CVE_json, f)
    print(CVE_json)

if __name__ == '__main__':
    get_CVE()